package com.bytedance.improvingroad.refecttion

import android.app.Activity
import android.view.View

/**
 * Created by chenxiong
 * date 12/2/21
 */
object ViewIdInject {
    fun injectView(activity: Activity) {
        activity.javaClass.declaredFields.forEach { field ->
            if (field.isAnnotationPresent(AutoWired::class.java)) {
                val autoWiredId = field.getAnnotation(AutoWired::class.java)
                val view = activity.findViewById<View>(autoWiredId.id)
                field.isAccessible = true
                field.set(activity,view)
            }
        }
    }
}